#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;

enum class IOS
{
    OPEN,
    NOT_OPEN
};

class File
{
public:
    File()
    {
        m_flag = IOS::NOT_OPEN;
    }

    File(string filename, string mode)
    {
        m_fp = fopen(filename.c_str(), mode.c_str());

        if (m_fp == nullptr)
        {
            m_flag = IOS::NOT_OPEN;
            throw("open file error");
        }

        m_flag = IOS::OPEN;
    }

    ~File()
    {
        fclose(m_fp);
    }

    void open_file(string filename, string mode)
    {
        m_fp = fopen(filename.c_str(), mode.c_str());

        if (m_fp == nullptr)
        {
            m_flag = IOS::NOT_OPEN;
            throw("open file error");
        }

        m_flag = IOS::OPEN;
    }
    char get_char()
    {
        char temp;
        
        if (m_flag == IOS::OPEN)
        {
            temp = fgetc(m_fp);
        }
        else
        {
            throw("file is not open!\n");
        }

        return temp;
    }
    string get_line()
    {

    }
    string get_all()
    {

    }
    template <typename U>
    U get_bin()
    {
        U temp;
    }

    void write_data(string data)
    {

    }
    template <typename T>
    void write_bin(const T &data)
    {

    }

    void seek(long offset, int whence = SEEK_SET)
    {
        fseek(m_fp, offset, whence);
    }
    
    void copy(const File &file);

    bool operator!()
    {
        return m_flag == IOS::OPEN;
    }

    //= + 
private:
    FILE *m_fp;
    IOS m_flag;
};

int main(int argc, char **argv)
{
    File file("a.txt","w+");
    file.write_data("hello");
    file.write_bin<int>(5);

    return 0;
}